package com.sky.controller.admin;

import com.sky.dto.SetMealDTO;
import com.sky.dto.SetMealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetMealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author: test
 * @date: 2025/3/28 16:54
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetMealController {

    private final SetMealService setMealService;

    public SetMealController(SetMealService setMealService) {
        this.setMealService = setMealService;
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result add(@RequestBody SetMealDTO setMealDTO) {
        log.info("新增套餐:{}", setMealDTO);
        setMealService.add(setMealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("套餐条件分页查询")
    public Result<PageResult> queryPageOnConditional(SetMealPageQueryDTO setMealPageQueryDTO) {
        PageResult pageResult = setMealService.queryPageOnConditional(setMealPageQueryDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result delete(@RequestParam("ids") List<Long> ids) {
        log.info("批量删除套餐:{}", ids);
        setMealService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetMealVO> getById(@PathVariable("id") Long id) {
        log.info("根据id查询套餐:{}", id);
        SetMealVO setMealVO = setMealService.getById(id);
        return Result.success(setMealVO);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetMealDTO setMealDTO) {
        log.info("修改套餐:{}", setMealDTO);
        setMealService.update(setMealDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("起售停售套餐")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        log.info("起售停售套餐:{},{}", status, id);
        setMealService.startOrStop(status, id);
        return Result.success();
    }
}